#ifndef __ASM_H__
#define __ASM_H__

//========================汇编相关定义
#define BEGIN_FUNC(_name)    \
    .global _name;           \
    .type _name, %function;  \
    _name:

#define END_FUNC(_name)          \
    .size _name, .- _name

#define BEGIN_FUNC_STATIC(_name) \
    .type _name, %function;      \
    _name:

#define END_FUNC_STATIC(_name)   \
    .size _name, .- _name

#define SYMBOL_TO_STR(name) #name

#define io_out8(port, data)                          \
    do                                               \
    {                                                \
        __asm__ __volatile__("out %b0, %w1\n\t"      \
                             :                       \
                             : "a"(data), "Nd"(port) \
                             : "memory");            \
    } while (0)


#define io_in8(port, data)                     \
    do                                         \
    {                                          \
        __asm__ __volatile__("in %w1, %b0\n\t" \
                             : "=a"(data)      \
                             : "Nd"(port)      \
                             : "memory");      \
    } while (0)

#define io_in32(port, data)                    \
    do                                         \
    {                                          \
        __asm__ __volatile__("in %w1, %k0\n\t" \
                             : "=a"(data)      \
                             : "Nd"(port)      \
                             : "memory");      \
    } while (0)

#define io_out32(port, data)                         \
    do                                               \
    {                                                \
        __asm__ __volatile__("out %k0, %w1\n\t"      \
                             :                       \
                             : "a"(data), "Nd"(port) \
                             : "memory");            \
    } while (0)




#define cli_asm()                           \
     __asm__ __volatile__("cli"             \
                          : : : "memory")
#define sti_asm()                           \
     __asm__ __volatile__("sti"             \
                          : : : "memory")
#endif